/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2011
 */

package com.tech15.core.model;

import javacommon.base.BaseEntity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.validator.constraints.Length;

import cn.org.rapid_framework.util.DateConvertUtils;

/**
 * @author 胡作正 email:zuozhenghu@sina.com
 * @version 1.0
 * @since 1.0
 */


@Entity
@Table(name = "ATTACH")
public class Attach extends BaseEntity implements java.io.Serializable{
	private static final long serialVersionUID = 5454155825314635342L;
	
	//alias
	public static final String TABLE_ALIAS = "附件";
	public static final String ALIAS_ATTACHID = "序号";
	public static final String ALIAS_NAME = "附件名称";
	public static final String ALIAS_PATH = "附件路径";
	public static final String ALIAS_ATTACH_SIZE = "附件大小";
	public static final String ALIAS_CONT_TYPE = "内容类型";
	public static final String ALIAS_POSTFIX = "后缀";
	public static final String ALIAS_USERID = "上传者";
	public static final String ALIAS_UP_TIME = "上传时间";
	public static final String ALIAS_TABLENAME = "表名称";
	public static final String ALIAS_TABLEID = "表序号";
	
	//date formats
	public static final String FORMAT_UP_TIME = DATE_TIME_FORMAT;
	

	//可以直接使用: @Length(max=50,message="用户名长度不能大于50")显示错误消息
	//columns START
    /**
     * 序号       db_column: ATTACHID 
     */ 	
	@Length(max=32)
	private java.lang.String attachid;
    /**
     * 附件名称       db_column: NAME 
     */ 	
	@Length(max=300)
	private java.lang.String name;
    /**
     * 附件路径       db_column: PATH 
     */ 	
	@Length(max=300)
	private java.lang.String path;
    /**
     * 附件大小       db_column: ATTACH_SIZE 
     */ 	
	
	private Long attachSize;
    /**
     * 内容类型       db_column: CONT_TYPE 
     */ 	
	@Length(max=20)
	private java.lang.String contType;
    /**
     * 后缀       db_column: POSTFIX 
     */ 	
	@Length(max=15)
	private java.lang.String postfix;
    /**
     * 上传者       db_column: USERNAME 
     */ 	
	private Long userid;
    /**
     * 上传时间       db_column: UP_TIME 
     */ 	
	
	private java.util.Date upTime;
    /**
     * 表名称       db_column: TABLENAME 
     */ 	
	@Length(max=40)
	private java.lang.String tablename;
    /**
     * 表序号       db_column: TABLEID 
     */ 	
	@Length(max=32)
	private java.lang.String tableid;
	//columns END


	public Attach(){
	}

	public Attach(
		java.lang.String attachid
	){
		this.attachid = attachid;
	}

	

	public void setAttachid(java.lang.String value) {
		this.attachid = value;
	}
	
	@Id @GeneratedValue(generator="custom-id")
	@GenericGenerator(name="custom-id", strategy = "uuid.hex")
	@Column(name = "ATTACHID", unique = true, nullable = false, insertable = true, updatable = true, length = 32)
	public java.lang.String getAttachid() {
		return this.attachid;
	}
	
	@Column(name = "NAME", unique = false, nullable = true, insertable = true, updatable = true, length = 300)
	public java.lang.String getName() {
		return this.name;
	}
	
	public void setName(java.lang.String value) {
		this.name = value;
	}
	
	@Column(name = "PATH", unique = false, nullable = true, insertable = true, updatable = true, length = 300)
	public java.lang.String getPath() {
		return this.path;
	}
	
	public void setPath(java.lang.String value) {
		this.path = value;
	}
	
	@Column(name = "ATTACH_SIZE", unique = false, nullable = true, insertable = true, updatable = true, length = 22)
	public Long getAttachSize() {
		//return new Long(Math.round(this.attachSize/1024*100)/100);
		return this.attachSize;
	}
	
	public void setAttachSize(Long value) {
		this.attachSize = value;
	}
	
	@Transient
	public String getFilesize() {
		/*if(this.attachSize>0 && this.attachSize<1024){
			return this.attachSize+"KB";
		}else{
			return (this.attachSize/1024)+"M";
		}*/
		return (this.attachSize/1024)+"KB";
	}
	public void setFilesize(String value) {
		
	}
	
	@Column(name = "CONT_TYPE", unique = false, nullable = true, insertable = true, updatable = true, length = 20)
	public java.lang.String getContType() {
		return this.contType;
	}
	
	public void setContType(java.lang.String value) {
		this.contType = value;
	}
	
	@Column(name = "POSTFIX", unique = false, nullable = true, insertable = true, updatable = true, length = 15)
	public java.lang.String getPostfix() {
		return this.postfix;
	}
	
	public void setPostfix(java.lang.String value) {
		this.postfix = value;
	}
	
	@Column(name = "USERID", unique = false, nullable = true, insertable = true, updatable = true, length = 22)
	public Long getUserid() {
		return this.userid;
	}
	
	public void setUserid(Long value) {
		this.userid = value;
	}
	
	@Transient
	public String getUpTimeString() {
		return DateConvertUtils.format(getUpTime(), FORMAT_UP_TIME);
	}
	public void setUpTimeString(String value) {
		setUpTime(DateConvertUtils.parse(value, FORMAT_UP_TIME,java.util.Date.class));
	}
	
	@Column(name = "UP_TIME", unique = false, nullable = true, insertable = true, updatable = true, length = 7)
	public java.util.Date getUpTime() {
		return this.upTime;
	}
	
	public void setUpTime(java.util.Date value) {
		this.upTime = value;
	}
	
	@Column(name = "TABLENAME", unique = false, nullable = true, insertable = true, updatable = true, length = 40)
	public java.lang.String getTablename() {
		return this.tablename;
	}
	
	public void setTablename(java.lang.String value) {
		this.tablename = value;
	}
	
	@Column(name = "TABLEID", unique = false, nullable = true, insertable = true, updatable = true, length = 32)
	public java.lang.String getTableid() {
		return this.tableid;
	}
	
	public void setTableid(java.lang.String value) {
		this.tableid = value;
	}
	

	public String toString() {
		return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
			.append("Attachid",getAttachid())
			.append("Name",getName())
			.append("Path",getPath())
			.append("AttachSize",getAttachSize())
			.append("ContType",getContType())
			.append("Postfix",getPostfix())
			.append("Username",getUserid())
			.append("UpTime",getUpTime())
			.append("Tablename",getTablename())
			.append("Tableid",getTableid())
			.toString();
	}
	
	public int hashCode() {
		return new HashCodeBuilder()
			.append(getAttachid())
			.toHashCode();
	}
	
	public boolean equals(Object obj) {
		if(obj instanceof Attach == false) return false;
		if(this == obj) return true;
		Attach other = (Attach)obj;
		return new EqualsBuilder()
			.append(getAttachid(),other.getAttachid())
			.isEquals();
	}
	
	private String username;

	@Transient
	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}
	
}

